perm filename EQNS.MF[MF,DEK] blob sn#751801 filedate 1984-04-28 generic text, type T, neo UTF8
% this handout shows the file for the lecture on equations
% lines that begin "%##" were typed by METAFONT to show its
% internal operations as it solves equations.

delimiters();			% now ( and ) act like parentheses
vardef z@#=(x@#,y@#) enddef;	% now, e.g., z1a stands for (x1a,y1a)

pausing:=1;		% METAFONT will pause as we look at the rest of the file
tracingequations:=1;
 
h=v=1;		% a simple pair of equations
%## v=1		% you see this because "tracingequations" is > 0
%## h=1
3r=2s=18;	% slightly less simple
%## s=9
%## r=6
z1=(12,17);	% z1 stands for (x1,y1); this is like two equations
%## y1=17
%## x1=12
x2+2y2=16;	% here we can't solve for x2 and y2 all at once
%## y2=-0.5x2+8	% so METAFONT makes y2 "dependent" on x2
x2-y2=1;	% this equation now becomes "x2-(-0.5x2+8)=1)"
%## x2=6	% hence METAFONT can now solve for x2
%#### y2=5	% and this in turn gives the value of y2
x2:=16-2y3;	% an assignment (:=) undefines x and then makes x=16-2y3
%## y3=-0.5x2+8
z2=z3;		% now we set x2=x3 and y2=y3; several things happen:
%## x2=6
%#### ypart %CAPSULE12866=5	% capsules are internal expressions that are
%#### xpart %CAPSULE12885=6	% involved in METAFONT's mysterious calculations
%#### y3=5
%## x3=6
%#### xpart %CAPSULE12866=6
 
z4=.5[z1,z2];	% recall that z1=(12,17) and z2=(6,5)
%## y4=11
%## x4=9
z5=1/3[z1,z2];
%## y5=13.00006
%## x5=10.00003
z6=1/3[z7,z8];
%## y6=0.66667y7+0.33333y8
%## x6=0.66667x7+0.33333x8
z7=z9+z1;
%## y7=y9+17
%## x7=x9+12
tracingonline:=1; showdependencies;	% this shows all variables that
%x7=x9+12				% are currently dependent on others
%y7=y9+17				% at the moment, x7,xy7,x6,y6 are dependent
%x6=0.33333x8+0.66667x9+8.00006		% and x8,y8,x9,y9 are independent.
%y6=0.33333y8+0.66667y9+11.33342	% (every equation removes one independent)
%! OK.	% this means METAFONT has shown all the things that were asked.
z7=0[z1,z2];	% in other words, z7=z1
%## y9=0
%#### y7=17
%## x9=0
%#### x7=12
z8=2[z1,z2];	% z1 plus twice (z2-z1)
%## y8=-7
%#### y6=9.00012
%## x8=0
%#### x6=8.00006
showdependencies;
%! OK.	% now there aren't any dependencies left

z11=(10,20); z12=(100,65); z13=(30,65); z14=(49,8);
%## y11=20
%## x11=10
%## y12=65
%## x12=100
%## y13=65
%## x13=30
%## y14=8
%## x14=49
% let's try to find the point z10 on the line z11..z12 and also on z13..z14:
z10=a[z11,z12];		% this states that z10 is somewhere on the line z11..z12
%## a=0.02222y10-0.44444
%## y10=0.5x10+14.99992
z10=b[z13,z14];		% and this states that it's somewhere on z13..z14.
%## b=-0.00877x10+0.8772
%## x10=39.9999
%#### b=0.52632
%#### ypart %CAPSULE12452=34.99971
%#### xpart %CAPSULE12452=39.9999
%#### y10=34.99988
%#### a=0.33333
% So METAFONT solved the equations.
% [The true value is (x10,y10)=(40,35);
% METAFONT's solution is off by a tiny fraction of a pixel.]

numeric a,b;	% this is one way to undefine a,b so they can be used again

x1=12; % this causes the error message "! Redundant equation."
% and the help message is:	I already knew that this equation was true.
%				But perhaps no harm has been done; let's continue.
z1=(12,17);	% a redundant equation about a pair does not generate an error.
z1=(13,17);	% but this causes one: ! Inconsistent equation (off by 1).

x+2y=x+3w=6;	% here we introduce three variables not seen before
%## w=-0.33333x+2
%## y=-0.5x+3
numeric x;	% it's bad to undefine x now, since w and y depend on it.
%	! Variable x should have been defined.
%	l.35 numeric x;
%               
%	? h
%	Oh dear. You've got some partially-evaluated expressions
%	depending on this variable, but now it's essentially
%	disappearing before getting any value! I shall try to
%	keep going by assuming that a default value had been given.
%#### y=3	% METAFONT essentially sets x=0 in the formulas for y and w.
%#### w=2
string s[];	% this says that s[i] will be a string, for all numbers i

s1=s2; s3=s4; s1=s3;	% equations can be given for nonnumeric variables too

show s1,s2,s3,s4;
% s1 is shown as "unknown string s4"
% s2 is shown as "unknown string s1"
% s3 is shown as "unknown string s2"
% s4 is shown as "unknown string s3"
% hence all four strings are unknown but equal to each other

showvar s;	% here's a faster way to show all of the "s" variables
%s=9		% s without a subscript was defined to equal 9, long ago
%s[]=unknown string	% s with a subscript will be of type string
%s1=unknown string s4	% this is the current "value" of s1
%s2=unknown string s1	% this is the current "value" of s2
%s3=unknown string s2	% this is the current "value" of s3
%s4=unknown string s3	% this is the current "value" of s4

s2="gosh";	% now this makes all four equivalent strings equal to "gosh"
showvar s;
%s=9
%s[]=unknown string
%s1="gosh"
%s2="gosh"
%s3="gosh"
%s4="gosh"	% see?